
    //获取父层传来的值
    var parentId = 0,small = 0, parentinputname= "";//当前图片分类ID

    function child(objs){
        console.log(objs.inputname);
        parentinputname=objs.inputname;

    };

    new Vue({
        el: "#app",
        data: {
            categoryList:[],
            searchTitle:'',
            parentId:parentId,
            imageList:[],
            page:1,
            limit:18,
            loading:false,
            small:small,
            selectImages:[],
            selectImagesIDS:[],
            selectImageList:[],
            uploadInst:null,
        },
        watch:{
            page:function () {
                this.getImageList();
            },
        },
        methods:{
            //删除图片
            delImage:function(){
                var that=this;
                if(!this.selectImages.length) return;
                layList.layer.confirm('是否要删除选中图片？', {
                    btn: ['是的我要删除','我想想把'] //按钮
                }, function(){

                    console.log(that.selectImagesIDS);
                    layList.basePost(that.U({c:'directoryFile',a:'batchDelete'}),{ids:JSON.stringify(that.selectImagesIDS)},function (res) {
                        layList.msg(res.message);
                        that.getImageList();
                        that.$set(that,'selectImages',[]);
                        that.$set(that,'selectImagesIDS',[]);
                    },function (res) {
                        layList.msg(res.msg);
                    })
                })
            },
            //移动图片分类
            moveCate:function(){
                if(!this.selectImages.length) return;
                return this.getOpenWindow('移动文件',this.U({c:'directoryFile',a:'edit'})+'?imgaes='+this.selectImagesIDS);
            },
            //使用选中图片
            useImages:function(){
                if(!this.selectImages.length) return;
                if(typeof parent.$f != 'undefined'){
                    var value = parent.$f.getValue(parentinputname);//父级input 值
                    var list = value || [];
                    for(var i = 0;i < this.selectImages.length;i++){
                        if(value.indexOf(this.selectImages[i]) == -1) list.push(this.selectImages[i]);
                    }
                    parent.$f.changeField(parentinputname,list);
                    parent.$f.closeModal();
                }else{
                    parent.changeIMG(parentinputname,this.selectImageList[0]);
                   // parent.GetValue('我是子界面的数值'); //GetValue是父界面的Js 方法
                  var index = parent.layer.getFrameIndex(window.name);
                   // parent.layer.tips(this.selectImages[0], '#changeImg', {time: 5000});
                  //  parent.changeIMG('11',this.selectImages[0]);
                    parent.layer.close(index);
                }
            },
            //图片选中和取消
            changImage:function(item,index){
                var len = this.imageList.length,selectImages=[],selectImagesIDS=[],selectImageList=[];
                if(typeof parent.$f != 'undefined'){
                    //已有图片个数
                    var nowpics = parent.$f.getValue(parentinputname).length;
                    //设置最大个数
                    var maxlength = parent.$f.model()[parentinputname].rule.props.maxLength;
                    //已选图片个数
                    var selectlength = this.selectImages.length;
                    if(nowpics+selectlength >= maxlength && !item.isSelect){
                        return layList.msg('不能在选了');
                    }
                }
                this.$set(this.imageList[index],'isSelect',item.isSelect == undefined ? true : !item.isSelect);

                for (var i=0;i<len;i++){
                    if(this.imageList[i].isSelect === true) {
                        selectImages.push(small == 1 ? this.imageList[i]['url'] : this.imageList[i]['url']);
                        selectImagesIDS.push(this.imageList[i]['fileId']);
                        selectImageList.push(this.imageList[i]);
                        //console.log(this.imageList[i]);
                    }
                }

                this.$set(this,'selectImages',selectImages);
                this.$set(this,'selectImagesIDS',selectImagesIDS);
                this.$set(this,'selectImageList',selectImageList);
                //console.log('selectImages',this.selectImages);
                console.log('selectImageList',this.selectImageList);
            },
            //获取图片列表
            getImageList:function(){
                var that = this;
				//var web="http://xiaoguo.yzb.link";
                if(that.loading) return;
                that.loading = true;

                var index = layList.layer.load(1, {shade: [0.1,'#fff']});
                layList.baseGet(Feng.ctxPath + this.U({c:'directoryFile',a:'list',q:{directoryId:this.parentId,page:this.page,limit:this.limit}}),function (res) {
                    that.loading = false;
                    console.log(res.data);
                    that.$set(that,'imageList',res.data);

                    layList.layer.close(index);
                   if(that.page == 1){
                       layList.laypage.render({
                           elem: that.$refs.image_page
                           ,count: res.count
                           ,limit:that.limit
                           ,theme: '#1E9FFF',
                           jump:function (obj) {
                               that.page=obj.curr;
                           }
                       });
                   }
                },function () {
                    that.loading = false;
                    layList.layer.close(index);
                });
            },
            //查询分类
            search:function(){
//                if(!this.searchTitle) return layList.msg('请输入搜索内容！');
                this.getCategoryList();
            },
            //打开和关闭树形
            OpenTree:function(item,index){
                this.parentId = item.directoryId;
                console.log('id',item.directoryId);

                if(item.child.length){ //判断是否有子分类
                    item.isOpen == undefined ? false : item.isOpen;
                    this.$set(this.categoryList[index],'isOpen',!item.isOpen);
                }else{
                    this.page = 1;
                    this.$set(this,'selectImages',[]);
                    this.$set(this,'selectImagesIDS',[]);
                    this.getImageList();
                }
                this.uploadInst.reload({
                    url:Feng.ctxPath +this.U({c:'oss',a:'uploadToDir'})+'?directoryId='+this.parentId +'&isUser=0'
                });
            },
            //组装URL
            U:function(opt){
                opt = typeof opt == 'object' ? opt : {};
                return layList.U({c:opt.c||'',a:opt.a || '',q:opt.q || {},p:opt.q || {}});
                //return layList.U({a:opt.a || '',q:opt.q || {},p:opt.q || {}});
            },



            //获取分类
            getCategoryList:function(){
                var that=this;
             /*   layList.baseGet(that.U({c:'directory',a:'list',q:{name:this.searchTitle}}),function (res) {
                    that.$set(that,'categoryList',res.data);
                });*/
           //  console.log('1111');
           //      layList.baseGet(that.U({c:'directory',a:'listAllForChild',q:{name:this.searchTitle}}),function (res) {
           //          that.$set(that,'categoryList',res.data);
           //      })

                layList.baseGet(Feng.ctxPath +"/directory/listAllForChild" ,function (res) {
                    that.$set(that,'categoryList',res.data);
                })

            },
            //鼠标移入显示图标
            changeActive:function(item,indexK,index){
               // console.log('index',index);
                if(index)
                    this.$set(this.categoryList[indexK]['child'],'isShow',true);
                else
                    this.$set(this.categoryList[indexK],'isShow',true);
            },
            //鼠标移出隐藏
            removeActive:function(item,indexK,index){
                if(index)
                    this.$set(this.categoryList[indexK]['child'],'isShow',false);
                else
                    this.$set(this.categoryList[indexK],'isShow',false);
            },
            //添加分类
            addCategory:function (item,parentId) {
                item = item == undefined ? {} : item;
                var directoryId = item.directoryId == undefined ? 0 : item.directoryId,
                    parentId = parentId == undefined ? 0 : parentId;
                return this.getOpenWindow(item.name ? item.name+'编辑' : '新增分类',this.U(Feng.ctxPath + {c:'directory',a:'add',q:{directoryId:parentId ==0 ? directoryId : parentId }}));
            },
            //修改分类
            updateCategory:function(item,parentId){
                item = item == undefined ? {} : item ;
                parentId = parentId == undefined ? 0 : parentId;
                return this.getOpenWindow(item.name+'编辑',this.U(Feng.ctxPath + {c:'directory',a:'edit',q:{directoryId:item.directoryId}}));
            },
            //删除分类
            delCategory:function (item,parentId) {
                var that=this;
                if(item.child.length && item.child.length!="" ) return layList.msg('请先删除子分类再尝试删除此分类！');
                layList.layer.confirm('是否要删除['+item.name+']分类？', {
                    btn: ['是的我要删除','我想想把'] //按钮
                }, function(){
                    layList.baseGet(Feng.ctxPath +that.U({c:'directory',a:'delete',q:{directoryId:item.directoryId}}),function (res) {
                        layList.msg(res.message,function () {
                            that.getCategoryList();
                        });
                    });
                });
            },
            //打开一个窗口
            getOpenWindow:function(title,url,opt){
                opt = opt == undefined ? {w:580,h:400} : opt;
                return layList.layer.open({
                    type: 2,
                    title: title,
                    shade: [0],
                    area: [opt.w+"px" , opt.h+'px'],
                    anim: 2,
                    content: [url, 'no'],
                    end: function (){
                       location.reload();
                       // this.getCategoryList();
                    }

                });
            },
            //回调
            SuccessCateg:function () {
                this.getCategoryList();
            },
            uploal:function () {
                var that=this;
                this.uploadInst=layList.upload.render({
                    elem: this.$refs.upload
                    ,url: Feng.ctxPath +this.U({c:'oss',a:'uploadToDir'})+'?directoryId='+this.parentId +'&isUser=0'
                    ,multiple: true
                    ,accept: 'file'
                    ,auto:true
                    ,size: 2097152 //限制文件大小，单位 KB
                    ,done: function(res){
                        layList.layer.msg(res.message,{time:3000});
                        that.getImageList();
                    }
                });
            }
        },
        mounted:function () {
            this.getCategoryList();
            this.getImageList();
            window.SuccessCateg = this.SuccessCateg;
            this.uploal();
        }
    })